package com.easpeed.comon.photo;

import android.content.Intent;

import androidx.fragment.app.FragmentManager;

/**
 * Created by bigyu on 2019/6/25 0025 10:34
 * onactivityResult的回调处理
 */
public class AvoidOnResult {

    private static final String TAG = "AvoidOnResult";

    private AvoidOnResultFragment avoidOnResultFragment;


    public AvoidOnResult(FragmentManager fragmentManager) {
        avoidOnResultFragment = (AvoidOnResultFragment) fragmentManager.findFragmentByTag(TAG);
        if (avoidOnResultFragment == null) {
            avoidOnResultFragment = new AvoidOnResultFragment();
            FragmentManager manager = fragmentManager;
            manager.beginTransaction()
                    .add(avoidOnResultFragment, TAG)
                    .commitAllowingStateLoss();
            manager.executePendingTransactions();
        }
    }

    public void startForResult(Intent intent, int requestCode, Callback callback) {
        avoidOnResultFragment.startForResult(intent, requestCode, callback);
    }


    public interface Callback {
        void onActivityResult(int requestCode, int resultCode, Intent data);
    }
}
